from rest_framework import serializers
from curriculum.models import Course, CourseTag, Chapter, CourseNode, Follow, UserSections, CommentReply, Comment
from goods.models import Sections
from user.models import User


class CourseSerializer(serializers.ModelSerializer):
    class Meta:
        model = Course
        fields = '__all__'


class CourseTagializer(serializers.ModelSerializer):
    class Meta:
        model = CourseTag
        fields = '__all__'


# CourseNode
class CourseNodeSerializer(serializers.ModelSerializer):
    class Meta:
        model = CourseNode
        fields = '__all__'


class ChapterSerializer(serializers.ModelSerializer):
    nodes = CourseNodeSerializer(many=True)

    class Meta:
        model = Chapter
        fields = '__all__'


# 关注序列化
class FollowSerializer(serializers.ModelSerializer):
    class Meta:
        model = Follow
        fields = '__all__'


class UserSectionsSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserSections
        fields = '__all__'


class SectionsSerializer(serializers.ModelSerializer):
    class Meta:
        model = Sections
        fields = '__all__'

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'username', 'img']

class CommentReplySerializer(serializers.ModelSerializer):
    # user = UserSerializer()
    # to_user = UserSerializer()

    class Meta:
        model = CommentReply
        fields = '__all__'


class CommentSerializer(serializers.ModelSerializer):
    # reply = CommentReplySerializer(many=True, read_only=True)

    class Meta:
        model = Comment
        fields = '__all__'